<template>
  <div>
    <h1>辅助函数访问模块</h1>
    <h2>{{num}}</h2>
    <h2>{{doubleNum}}</h2>
    <button @click="add">+</button>
    <button @click="add2">异步+</button>
  </div>
</template>

<script>
/**
 * 辅助函数访问vuex模块化的内容
 * 1、访问的state
 * 1)从vuex导入createNamespacedHelpers函数
 * 2)const {mapState}=createNamespacedHelpers('模块名')
 * 2、访问getters
 * 1)从vuex导入createNamespacedHelpers函数
 * 2）const {mapGetters}=createNamespacedHelpers('模块名')
 */
import {createNamespacedHelpers} from 'vuex'
const {mapState,mapGetters,mapMutations,mapActions}=createNamespacedHelpers('counterKey')
export default {
  computed:{
    ...mapState(['num']),
    ...mapGetters(['doubleNum'])
  },
  methods:{
    ...mapMutations(['incrementSync']),
    ...mapActions({"bieming":"incrementAsync"}),
    add(){
      this.incrementSync(3)
    },
    add2(){
      this.bieming(5)
    }
  }
}
</script>

<style>

</style>